﻿using System.Web;

namespace TweetSayingsLibrary.App.Entity
{
    public class Page
    {
        public static string FromControl(string name)
        {
            return HttpContext.Current.Request.Form[name];
        }

        public static long FromControlLong(string name, long defaultValue)
        {
            string s = HttpContext.Current.Request.Form[name];
            long l;
            if (long.TryParse(s, out l))
                return l;

            return defaultValue;
        }

        public static string FromQueryString(string name)
        {
            return HttpContext.Current.Request.QueryString[name];
        }

        public static int FromQueryStringInt(string name, int defaultValue)
        {
            int i;
            if (int.TryParse(HttpContext.Current.Request.QueryString[name], out i) == false)
                i = defaultValue;

            return i;
        }

        public static long FromQueryStringLong(string name, long defaultValue)
        {
            long i;
            if (long.TryParse(HttpContext.Current.Request.QueryString[name], out i) == false)
                i = defaultValue;

            return i;
        }
    }
}